(function() {	
	Wallet.widget.StatisticTabView = function(el, config) {
		Wallet.lang.applyIf(config, {
			orientation: "left",
			activeIndex: 0
		});
		
		Wallet.widget.StatisticTabView.superclass.constructor.call(this, el, config);	
	}
	
	var Lang = YAHOO.lang,
		TabView = YAHOO.widget.TabView,
		StatisticTabView = Wallet.widget.StatisticTabView;
	
	Lang.extend(StatisticTabView, TabView, {
		init: function(el, attr) {
			StatisticTabView.superclass.init.call(this, el, attr);
			
			this.initComponents();
			this.initListeners();
		},
		initComponents: function() {
			if (this.lazyLoad) {
				var tab = this.get("activeTab");
				var contentEl = tab.get("contentEl");
				this.onEventActiveTabChange({
					type: "activeTabChange",
					newValue: tab,
					prevValue: tab
				});
			} else {
				
			}
		},
		initListeners: function() {
			this.addListener("activeTabChange", this.onEventActiveTabChange);
		},
		initAttributes: function(attr) {
			DashBoardTabView.superclass.initAttributes.call(this, attr);
			
			this.setAttributeConfig("lazyLoad", {
	            value: attr.lazyLoad || true,
	            method: function(value) {
	            	this.lazyLoad = value;
	            },
	            validator: function(value) {
	            	return Lang.isBoolean(value);
	            }
        	});
		},
		onEventActiveTabChange: function(evt) {
			var newTab = evt.newValue;
			if (newTab.dataTable == null) {
				var contentEl = newTab.get("contentEl");
				
				var el = YAHOO.util.Dom.getElementsByClassName("month-statistic-data-table", "div", contentEl)[0];
				var dataSource = YAHOO.util.Dom.getElementsByClassName("month-statistic-data-source", "table", contentEl)[0];	
			
				if (el == null || dataSource == null) {
					throw "No DataTable and DataSource template found";
					return false;	
				}
				
				var dataTable = new Wallet.widget.StatisticDataTable(el, {
					dataSource: dataSource
				}); 
				
				newTab.dataTable = dataTable;
			}
		}
	});
	
}());